<Workspace Version="1.3.4.6666" X="-2891.935998084" Y="6.64680975585378" zoom="1.10027931340777" ScaleFactor="1" Name="Home" Description="" RunType="Manual" RunPeriod="1000" HasRunWithoutCrash="True">
  <NamespaceResolutionMap>
    <ClassMap partialName="Element" resolvedName="Revit.Elements.Element" assemblyName="RevitNodes.dll" />
    <ClassMap partialName="Math.PI" resolvedName="DSCore.Math" assemblyName="DSCoreNodes.dll" />
    <ClassMap partialName="Math" resolvedName="DSCore.Math" assemblyName="DSCoreNodes.dll" />
  </NamespaceResolutionMap>
  <Elements>
    <DSRevitNodesUI.Categories guid="325bb490-ee17-4962-be6d-4446ed26db83" type="DSRevitNodesUI.Categories" nickname="Categories" x="-192.163862166151" y="166.275821388319" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="True" IsFrozen="false" isPinned="false" index="444:SecurityDevices" />
    <DSRevitNodesUI.ElementsOfCategory guid="7ff05dba-f332-4bce-a4b0-a0da38fd8ed8" type="DSRevitNodesUI.ElementsOfCategory" nickname="All Elements of Category" x="137.126650690878" y="166.203193174062" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false">
      <PortInfo index="0" default="False" />
    </DSRevitNodesUI.ElementsOfCategory>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="325e6658-b4df-4524-8a34-083dcee8e37a" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="869.814641533751" y="380.662794058887" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="&quot;Стержень заземления в сборе&quot;;" ShouldFocus="false" />
    <Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="aef60409-ae56-4691-97b1-148f23e7dc78" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="String.Contains" x="1184.46984040004" y="275.955820320965" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="DSCoreNodes.dll" function="DSCore.String.Contains@string,string,bool">
      <PortInfo index="0" default="False" />
      <PortInfo index="1" default="False" />
      <PortInfo index="2" default="True" />
    </Dynamo.Graph.Nodes.ZeroTouch.DSFunction>
    <Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="2cf549ba-72db-4280-b327-7083369b1e69" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="List.FilterByBoolMask" x="1431.70224744253" y="171.26695302704" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="DSCoreNodes.dll" function="DSCore.List.FilterByBoolMask@var[]..[],var[]..[]">
      <PortInfo index="0" default="False" />
      <PortInfo index="1" default="False" />
    </Dynamo.Graph.Nodes.ZeroTouch.DSFunction>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="86ab2518-dac1-48c6-8447-2d06b9d2653a" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="1728.35510684019" y="176.102211021817" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a.GetParameterValueByName(&quot;Глубина залегания фактическая&quot;);" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="70ed632f-a62b-4727-b6c3-f10177baf6d3" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="d" x="2070.1866859396" y="275.653874469136" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a.GetParameterValueByName(&quot;ADSK_Размер_Диаметр&quot;);" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="aaeda1d3-c782-4cea-bcdd-4e7a8d7039c2" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="1722.74604201317" y="274.047254388609" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a.GetParameterValueByName(&quot;Тип&quot;);" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="c6657744-5a1d-4462-a42e-e11f08225813" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="Count" x="2333.87097870964" y="86.3280014022481" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="BuiltIn" function="Count@var[]..[]">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.ZeroTouch.DSFunction>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="498f0abe-19ae-4cf6-861e-7b64985ab105" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="2339.39845392848" y="176.715505224774" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a[0]/1000;" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="79f15537-e2bb-4d73-bb3f-cf923bb5a707" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="2543.40277645086" y="275.229008287615" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a[0]/1000;" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <PythonNodeModels.PythonNode guid="937f126f-076f-4b52-9744-e24c837b8ebf" type="PythonNodeModels.PythonNode" nickname="Python Script" x="2981.06243983026" y="-21.8267568236366" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="true" inputcount="4">
      <PortInfo index="0" default="False" />
      <PortInfo index="1" default="False" />
      <PortInfo index="2" default="False" />
      <PortInfo index="3" default="False" />
      <Script>import clr
import math
from math import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *
from Autodesk.Revit.DB import MEPSystem
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore.List import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
clr.AddReference("System")
from System.Collections.Generic import List 
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.DB.Structure import *
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
 
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
collector = FilteredElementCollector(doc)
filter = ElementCategoryFilter(BuiltInCategory.OST_DuctCurves) 
all_ducts=collector.WherePasses(filter).WhereElementIsNotElementType().ToElements()
vertLen = IN[0]
diameter = IN[1]
count = IN[2]
deptH = IN[3]
gorDucts = []
a = []
vertLengths = []
depthGors = []
lenGors = []
vertDs = []
widthGors = []
countRs = []
lens = []
gorResistances = []
gR = []
totalResistances = []
tR = []
offsets = []


TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(len(all_ducts)):
	if all_ducts[i].LookupParameter("OBO_Горизонтальный заземлитель").AsInteger() == 1:
		gorDucts.append(all_ducts[i])
	
for element in gorDucts:
	topResistance = element.LookupParameter("OBO_Удельное сопротивление верхнего слоя грунта").AsInteger()				# Значение Удельного сопротивления верхнего слоя грунта                    
	bottomResistance = element.LookupParameter("OBO_Удельное сопротивление нижнего слоя грунта").AsInteger()			# Значение удельного сопротивления нижнего слоя грунта
	k_vertEnv = element.LookupParameter("OBO_Климатический коэффициент для вертикального заземлителя").AsDouble()		# Климатический коэффициент для вертикального заземлителя
	k_gorEnv = element.LookupParameter("OBO_Климатический коэффициент для горизонтального заземлителя").AsDouble()		# Климатический коэффициент для горизонтального заземлителя
	depth_upper_layer = element.LookupParameter("OBO_Глубина верхнего слоя грунта").AsDouble()*304.8					# Глубина верхнего слоя грунта		
	vertLength = vertLen																								# Длина вертикального заземлителя
	vertLengths.append(vertLength)	
	depthGor = -((element.get_Parameter(BuiltInParameter.RBS_OFFSET_PARAM)).AsDouble())*304.8/1000						# Глубина горизонтального заземлителя		
	depthGors.append(depthGor)
	lengthGor = ((element.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH)).AsDouble())*304.8/1000						
	a.append(lengthGor)
	lenGor = fsum(a)																									# Длина горизонтального заземлителя	
	vertD = diameter																									# Диаметр вертикального заземлителя
	vertDs.append(vertD)
		
	hight = ((element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM)).AsDouble())*304.8/1000					# Высота горизонтального заземлителя
	width = ((element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM)).AsDouble())*304.8/1000						# Ширина горизонтального заземлителя
	
	if hight &gt;= width:
		widthGor = hight
	else:
		widthGor = width
	widthGors.append(widthGor)
	countR = count																										# Количество вертикальных заземлителей
	countRs.append(countR)
	len = deptH/2 + depthGor																							# Расстояние до центра вертикального заземлителя										
	lens.append(len)
	kiVert = element.LookupParameter("OBO_Коэффициент использования вертикальных заземлителей").AsDouble()
	kiGor = element.LookupParameter("OBO_Коэффициент использования горизонтальных заземлителей").AsDouble()	
	
	element.LookupParameter("OBO_Длина вертикального заземлителя").Set(vertLength/304.8)
	element.LookupParameter("OBO_Глубина горизонтального заземлителя").Set(depthGor/304.8)
	element.LookupParameter("OBO_Длина горизонтального заземлителя").Set(lengthGor/304.8)
	element.LookupParameter("OBO_Диаметр вертикального заземлителя").Set(vertD/304.8)
	element.LookupParameter("OBO_Ширина горизонтального заземлителя").Set(widthGor/304.8)
	element.LookupParameter("OBO_Количество вертикальных заземлителей").Set(countR)
	element.LookupParameter("OBO_Расстояние до центра вертикального заземлителя").Set(len/304.8)

	udResistance = (topResistance * k_vertEnv * bottomResistance * vertLength)/(topResistance * k_vertEnv * (vertLength - depth_upper_layer + depthGor) + bottomResistance * (depth_upper_layer-depthGor))		# Удельное сопротивление грунта
	verticalResistance = (udResistance / (2 * math.pi * vertLength)) * (math.log(2 * vertLength / vertD) + 0.5 * math.log((4 * len + vertLength) / (4 * len - vertLength)))										# Сопротивление вертикального заземлителя
	gorResistance2 = (udResistance / (2 * math.pi * lenGor)) * math.log((math.pow(lenGor, 2)) / (widthGor * depthGor))																							# Сопротивление горизонтального заземлителя
	totalResistance = ((verticalResistance / (countR * kiVert)) * gorResistance2 / kiGor) / ((verticalResistance / (countR * kiVert)) + gorResistance2 / kiGor)													# Сопротивление вертикального заземлителя
	
	element.LookupParameter("OBO_Удельное сопротивление грунта").Set(udResistance)
	element.LookupParameter("OBO_Сопротивление вертикального заземлителя").Set(verticalResistance)

	gorResistances.append(gorResistance2)
	totalResistances.append(totalResistance)
	
for r in gorResistances:
	rgor = gorResistances[-1]
	gR.append(rgor)
	
for tr in totalResistances:
	totres = totalResistances[-1]
	tR.append(rgor)
	
for el in gorDucts:
	el.LookupParameter("OBO_Сопротивление горизонтального заземлителя").Set(rgor)
	el.LookupParameter("OBO_Полное сопротивление заземляющего устройства").Set(totres)
TransactionManager.Instance.TransactionTaskDone()	

OUT = totres




</Script>
    </PythonNodeModels.PythonNode>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="78548e2a-e93b-4ed6-91ac-c6d04cd8a4f2" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="376.246348087174" y="279.228003835037" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a.GetParameterValueByName(&quot;Тип&quot;);" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
    <Dynamo.Graph.Nodes.CodeBlockNodeModel guid="4f714c58-5ad4-467c-949a-321d77a8f54c" type="Dynamo.Graph.Nodes.CodeBlockNodeModel" nickname="Code Block" x="718.65548897322" y="279.186153435753" isVisible="true" isUpstreamVisible="true" lacing="Disabled" isSelectedInput="False" IsFrozen="false" isPinned="false" CodeText="a.GetParameterValueByName(&quot;ADSK_Наименование&quot;);" ShouldFocus="false">
      <PortInfo index="0" default="False" />
    </Dynamo.Graph.Nodes.CodeBlockNodeModel>
  </Elements>
  <Connectors>
    <Dynamo.Graph.Connectors.ConnectorModel start="325bb490-ee17-4962-be6d-4446ed26db83" start_index="0" end="7ff05dba-f332-4bce-a4b0-a0da38fd8ed8" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="7ff05dba-f332-4bce-a4b0-a0da38fd8ed8" start_index="0" end="2cf549ba-72db-4280-b327-7083369b1e69" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="7ff05dba-f332-4bce-a4b0-a0da38fd8ed8" start_index="0" end="78548e2a-e93b-4ed6-91ac-c6d04cd8a4f2" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="325e6658-b4df-4524-8a34-083dcee8e37a" start_index="0" end="aef60409-ae56-4691-97b1-148f23e7dc78" end_index="1" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="aef60409-ae56-4691-97b1-148f23e7dc78" start_index="0" end="2cf549ba-72db-4280-b327-7083369b1e69" end_index="1" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="2cf549ba-72db-4280-b327-7083369b1e69" start_index="0" end="86ab2518-dac1-48c6-8447-2d06b9d2653a" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="2cf549ba-72db-4280-b327-7083369b1e69" start_index="0" end="aaeda1d3-c782-4cea-bcdd-4e7a8d7039c2" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="86ab2518-dac1-48c6-8447-2d06b9d2653a" start_index="0" end="c6657744-5a1d-4462-a42e-e11f08225813" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="86ab2518-dac1-48c6-8447-2d06b9d2653a" start_index="0" end="498f0abe-19ae-4cf6-861e-7b64985ab105" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="70ed632f-a62b-4727-b6c3-f10177baf6d3" start_index="0" end="79f15537-e2bb-4d73-bb3f-cf923bb5a707" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="aaeda1d3-c782-4cea-bcdd-4e7a8d7039c2" start_index="0" end="70ed632f-a62b-4727-b6c3-f10177baf6d3" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="c6657744-5a1d-4462-a42e-e11f08225813" start_index="0" end="937f126f-076f-4b52-9744-e24c837b8ebf" end_index="2" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="498f0abe-19ae-4cf6-861e-7b64985ab105" start_index="0" end="937f126f-076f-4b52-9744-e24c837b8ebf" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="498f0abe-19ae-4cf6-861e-7b64985ab105" start_index="0" end="937f126f-076f-4b52-9744-e24c837b8ebf" end_index="3" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="79f15537-e2bb-4d73-bb3f-cf923bb5a707" start_index="0" end="937f126f-076f-4b52-9744-e24c837b8ebf" end_index="1" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="78548e2a-e93b-4ed6-91ac-c6d04cd8a4f2" start_index="0" end="4f714c58-5ad4-467c-949a-321d77a8f54c" end_index="0" portType="0" />
    <Dynamo.Graph.Connectors.ConnectorModel start="4f714c58-5ad4-467c-949a-321d77a8f54c" start_index="0" end="aef60409-ae56-4691-97b1-148f23e7dc78" end_index="0" portType="0" />
  </Connectors>
  <Notes />
  <Annotations />
  <Presets />
  <Cameras>
    <Camera Name="Фоновый просмотр" eyeX="-17" eyeY="24" eyeZ="50" lookX="12" lookY="-13" lookZ="-58" upX="0" upY="1" upZ="0" />
  </Cameras>
</Workspace>